#define _init__c

#include    "includeAll.h"

void InitRegister (){

    TMOD = 0x11;		        //16bit timer0&timer1
	TH0 = (65536-7372)/256;	//2ms timer0 interrupt
	TL0 = (65536-7372)%256;
	TH1 = (65536-276)/256;		//20ms timer1 interrupt
	TL1 = (65536-276)%256;
	TH2 = (65536-230)/256;      //0.125ms==2khz timer2 interrupt
    TL2 = (65536-230)%256; 
    RCP2H = TH2  ;
    RCP2L = TL2  ;
		IPH=0x20;
	IP=0x20;
	ET0 = 1;			//timer0 interrupt enable
	TR0 = 1;			//timer0 running
	ET1 = 1;            //timer1 interrupt enable
	TR1 = 1;            //timer1 running
  ET2 = 1;            //timer2 interrupt enable
  TR2 = 1;            //timer2 running  
  EA=1;
}



void InitIoport (){
    

	P1MODL &=0x00;
	P1MODH &=0x00;
	PINMOD &=b1111_0000;
	P3MODL &=0x00;
	P3MODH &=0x00;
	//PINMOD &=b1111_1010;
	//P1MODL |=b0010_0000;
	//P1MODH |= b0000_1000;
	//P3MODH |= b0010_1010;
	//P3MODL = b0010_0000;
	
}


void ChangeToFastClk(void)
{
	CLKCON = 0x02;	//Clock div 1
	STPPCK = 0;
	STPFCK = 0;	
	_nop_();	
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	SELFCK = 1;
}

void Delay()
{

    hwTimer = 0x1fff;
    while (hwTimer--)
    {
        CLRWDT = 1; //clear watchdog
        CLRWDT = 1;
        CLRWDT = 1;
        CLRWDT = 1; //clear watchdog
        CLRWDT = 1;
        CLRWDT = 1;
    }
}